package com.gill.config;


import com.netflix.loadbalancer.IPing;
import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import com.netflix.loadbalancer.RoundRobinRule;
import com.netflix.niws.loadbalancer.NIWSDiscoveryPing;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

/**
 * 注入spring提供的用于RPC的RestTemplate
 **/
@Configuration
public class RestConfig {

    @Bean
    @LoadBalanced//使得注入的RestTemplate具有负载均衡功能
    public RestTemplate restTemplate(){
        return new RestTemplate();
    }

    /**
     * 指定负载均衡算法，不指定则默认是轮询
     */
    @Bean
    public IRule iRule(){
        return new RandomRule();
    }
}
